import { isLogin } from '@/utils/auth'
import { CacheAuthrizedToken } from '@/utils/cache'
import { defineStore } from 'pinia' 

export const useAuthStore = defineStore('auth', {
  state: () => {
    return { logined: isLogin() }
  },
  actions: {
    logout() {
      return new Promise((resolve) => {
        this.logined = false
        CacheAuthrizedToken.remove()
        resolve(true)
      })
    },
    login() {
      return new Promise((resovle) =>{
        setTimeout(()=>{
          CacheAuthrizedToken.set('2121')
          this.logined = true
          resovle(true)
        }, 2000)
      })
      
    },
    increment() {
      
      this.count++
    },
  },
})
export default useAuthStore